home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / nild.exe / NUMINP.H < prev    next >
C/C++ Source or Header  |  1992-08-29  |  2KB  |  84 lines

  1. // Copyright (C) 1992 James H. Price, All rights reserved
  2. //
  3. //  NUMINP.H
  4. //
  5. //    Header for NumInputLine class
  6. //
  7.  
  8. #if !defined( __NUMINP_H )
  9. #define __NUMINP_H
  10.  
  11. #define Uses_TInputLine
  12. #include <tv.h>
  13.  
  14. class TEvent;
  15.  
  16. //
  17. //  Mask characters:
  18. //
  19. //    u   digits ( 0,1,2 ... 9 ) only
  20. //    d   digits, initial minus sign
  21. //    f   digits, initial minus sign, decimal point
  22. //
  23. //  The mask character is passed as an argument to NumInput line to
  24. //  control what characters are accepted.  IntInputLine has a default
  25. //  argument of 'd'; DoubleInputLine has a default argument of 'f'.
  26. //
  27.  
  28.  
  29. template <class Type>
  30. class NumInputLine : public TInputLine {
  31.  
  32. public:
  33.  
  34.   NumInputLine( const TRect& r, int maxLen, char aMaskChar );
  35.  
  36.   virtual void getData( void *rec );
  37.   virtual void setData( void *rec );
  38.   virtual void handleEvent( TEvent& event );
  39.  
  40. private:
  41.  
  42.   char maskChar;
  43.  
  44.   virtual Boolean isValidChar( TEvent& event );
  45.  
  46.  
  47.   // pure virtual functions -- must be overridden
  48.   // in derived classes.  See IntInputLine and DoubleInputLine
  49.   // for examples of what these functions should do.
  50.  
  51.   virtual void numToStr( Type *rec, char *buf ) = 0;
  52.   virtual Type strToNum( char *s ) = 0;
  53.   virtual ushort dataSize() = 0;
  54.  
  55. };
  56.  
  57. class IntInputLine : public NumInputLine<int> {
  58.  
  59. public:
  60.  
  61.   IntInputLine( const TRect& r, int maxLen, char maskChar='d' );
  62.  
  63. private:
  64.  
  65.   void numToStr( int *rec, char *buf );
  66.   int strToNum( char *s );
  67.   ushort dataSize();
  68. };
  69.  
  70. class DoubleInputLine : public NumInputLine<double> {
  71.  
  72. public:
  73.  
  74.   DoubleInputLine( const TRect& r, int maxLen, char maskChar='f' );
  75.  
  76. private:
  77.  
  78.   void numToStr( double *rec, char *buf );
  79.   double strToNum( char *s );
  80.   ushort dataSize();
  81. };
  82.  
  83. #endif
  84.